<!DOCTYPE html>
<html>
  <head>
    <title>ajax02.html</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
    	function getXhr(){
    		var xhr=null;
    		if(window.XMLHttpRequest){
    			xhr=new XMLHttpRequest();
    		}else{
    			xhr=new ActiveXObject("Microsoft.XMLHttp");
    		}
    		return xhr;
    	}
    	
    	function getText(){
    		//1.获取Ajax对象
    		var xhr=getXhr();
    		//2.设置回调函数
    		xhr.onreadystatechange=function(){
    			if(xhr.readyState==4 && xhr.status==200){
    				var txt=xhr.responseText;
    				alert(txt);
    			}
    		};
    		//3.创建请求
    		xhr.open("get","get_text.do",true);
    		//4.发送请求
    		xhr.send(null);
    	}
    </script>
  </head>
  
  <body>
    	<a href="javascript:;" onclick="getText()">获取文本</a>
  </body>
</html>
